<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<script type="text/javascript" src="http://cpc.admicro.vn/vcm/ckeditor/ckeditor.js"></script>
<script src="http://cpc.admicro.vn/vcm/ckeditor/_samples/sample.js" type="text/javascript"></script>
<link href="http://cpc.admicro.vn/vcm/ckeditor/_samples/sample.css" rel="stylesheet" type="text/css" />
<div class="middle padtop10 myclear">
	<div class="page-content">
		
		<!-- bread crumb -->
		<p id="bread-crumb">
			<a href="<?php echo base_url();?>">
				<?php echo $lang['home']?>
			</a>
			<a href="<?php echo site_url('faqs');?>">
				<?php echo $lang['faqs'];?>
			</a>
			<?php echo $id > 0 ? $lang['edit_topic'] : $lang['add_topic'];?>
		</p>
		<!-- end bread crumb -->
		<h3>
			<?php echo $id > 0 ? $lang['edit_topic'] : $lang['add_topic'];?>
		</h3>
		<br style="clear:both;" />

		<form action="<?php echo site_url('faqs/addTopic');?>" method="post" onsubmit="return checkTopicPost();">
		<table width="100%" cellpadding="3" cellspacing="0">
		<tr>
			<td>
				<b><?php echo $lang['category']?>*</b> <select name="cat_id" id="cat_id" onchange="get_topics();" style="width:150px">
							<option value="0">-- Parent --</option>
							<?php foreach ($categories as $cat){?>
							<option value="<?php echo $cat->cat_id;?>" <?php if($cat->cat_id == $cat_id) echo 'selected="true"';?> <?php if($cat->parent_id == 0) echo 'disabled="disabled"';?>>
								<?php echo ($cat->parent_id > 0 ? '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|_' : '').$cat->name;?>
							</option>
							<?php }?>
						</select>
				&nbsp;<b><?php echo $lang['topic']?></b> <select name="parent_id" id="parent_id" style="width:150px">
							<option value="0">-- Parent --</option>
							<?php foreach ($topics['items'] as $cat){?>
							<option value="<?php echo $cat->id;?>" <?php if($cat->id == $parent_id) echo 'selected="true"';?>>
								<?php echo $cat->content;?>
							</option>
							<?php }?>
						</select>
			</td>
		</tr>
		<tr>
			<td><br />
				<b><?php echo $lang['content']?>:</b> <textarea rows="15" cols="50" name="content" ><?php echo $content;?></textarea>
				<script type="text/javascript">
				CKEDITOR.replace( 'content',
					{
						skin : 'v2'
					});      
		        </script>
			</td>
		</tr>
		<tr>
			<td><br />
				<input type="hidden" value="<?php echo $id;?>" name="id" />
				<input type="submit" value="<?php echo $lang['save'];?>">
				<input type="button" value="<?php echo $lang['cancel'];?>" onclick="window.location.href='<?php echo site_url('faqs');?>';">
			</td>
		</tr>
		</table>
		</form>
		</div>
	</div>
</div><br />
<script type="text/javascript">
function checkTopicPost()
{
	if($('#cat_id').val() == '0')
	{
		alert('<?php echo $lang['select_category'];?>');
		return false;
	}

	return true;
}
function get_topics()
{
	$.ajax({
		url: '<?php echo site_url('faqs/ajax_get_topics/')?>?catid=' + $('#cat_id').val(),
		success: function(data){
			$('#parent_id').html(data);
		}
	});
}
</script>